import requests
import json
from openpyxl import Workbook

wk = Workbook()
ws = wk.active
ws.append(["电影名","上映天数","票房"])

headers = {
    "user-agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36 Edg/96.0.1054.62"
}

url = "https://piaofang.maoyan.com/dashboard-ajax?orderType=0&uuid=17e29144691c8-0ed9311b56c489-4c607a68-144000-17e29144691c8&timeStamp=1641368877753&User-Agent=TW96aWxsYS81LjAgKFdpbmRvd3MgTlQgMTAuMDsgV2luNjQ7IHg2NCkgQXBwbGVXZWJLaXQvNTM3LjM2IChLSFRNTCwgbGlrZSBHZWNrbykgQ2hyb21lLzk2LjAuNDY2NC4xMTAgU2FmYXJpLzUzNy4zNiBFZGcvOTYuMC4xMDU0LjYy&index=627&channelId=40009&sVersion=2&signKey=38d323a8d88f4eccedc3cc1f5faba51d"

paramr = {
    "orderType": "0",
    "uuid":"17e29144691c8-0ed9311b56c489-4c607a68-144000-17e29144691c8",
    "timeStamp":"1641366765544",
    "User-Agent": "TW96aWxsYS81LjAgKFdpbmRvd3MgTlQgMTAuMDsgV2luNjQ7IHg2NCkgQXBwbGVXZWJLaXQvNTM3LjM2IChLSFRNTCwgbGlrZSBHZWNrbykgQ2hyb21lLzk2LjAuNDY2NC4xMTAgU2FmYXJpLzUzNy4zNiBFZGcvOTYuMC4xMDU0LjYy",
    "index":"591",
    "channelId": "40009",
    "sVersion": "2",
    "signKey": "d0d3d7ee5d59c98a5e22ede3b77cdccd"
}
response = requests.get(url,headers=headers,params=paramr)
ret=response.text
ret=json.loads(ret)
ret = ret["movieList"]["data"]["list"]
for i in ret:
    s=i["movieInfo"]
    name=s["movieName"]
    time=s["releaseInfo"]
    money=i["sumBoxDesc"]
    ws.append([name,time,money])
    print("电影名：{}，上映时间：{}，票房：{}。".format(name,time,money))
wk.save("data/电影票房.xlsx")


